//
//  SEGWinRecordDetailNormalCell.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/8/21.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGWinRecordDetailNormalCell.h"

@interface SEGWinRecordDetailNormalCell ()
/**
 描述标签
 */
@property (nonatomic, strong)UILabel *descLabel;

/**
 内容
 */
@property (nonatomic, strong)UILabel *contentLabel;

/**
 复制按钮
 */
@property (nonatomic, strong)UIButton *copyButton;
@end

@implementation SEGWinRecordDetailNormalCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = kColor_W;
    
    _descLabel = [[UILabel alloc] init];
    _descLabel.font = kFont_13;
    _descLabel.textColor = kColor_2;
    [self.contentView addSubview:_descLabel];
    [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.centerY.equalTo(self.contentView);
    }];
    
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.font = kFont_13;
    _contentLabel.textColor = kColor_1;
    [self.contentView addSubview:_contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(109);
        make.right.equalTo(self.contentView).offset(-15);
        make.centerY.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(14);
        make.bottom.equalTo(self.contentView).offset(-14);
    }];
}

- (void)setUpCellWithModel:(SEGWinRecordDetailModel *)model type:(SEGWinRecordDetailNormalCellType)type
{
    self.copyButton.hidden = YES;//默认不显示
    self.contentLabel.textColor = kColor_1;
    switch (type) {
        case SEGWinRecordDetailNormalCellType_Prize: {
            self.descLabel.text = @"奖品";
            self.contentLabel.text = model.prizeName;
            break;
        }
        case SEGWinRecordDetailNormalCellType_Act: {
            self.descLabel.text = @"活动";
            self.contentLabel.text = model.actName;
            break;
        }
        case SEGWinRecordDetailNormalCellType_Time: {
            self.descLabel.text = @"中奖时间";
            NSString *time = [SEGUtils stringDateByFormatString:@"yyyy年MM月dd日 HH:mm" withDate:[NSDate dateWithTimeIntervalSince1970:[model.winnerTime doubleValue]]];
            self.contentLabel.text = time;
            break;
        }
        case SEGWinRecordDetailNormalCellType_Status: {
            self.descLabel.text = @"奖品状态";
            // 奖品发放状态(1:已发放,2:未发放)
            if ([model.sendStatus isEqualToString:@"1"]) {
                self.contentLabel.text = @"已发放";
                self.contentLabel.textColor = kColor_T;
            } else {
                // 是否是失效状态
                if ([model isInvaildState]) {
                    self.contentLabel.textColor = kColor_3;
                    self.contentLabel.text = @"已失效";
                } else {
                    self.contentLabel.textColor = kColor_1;
                    self.contentLabel.text = @"未发放";
                }
            }
            break;
        }
        case SEGWinRecordDetailNormalCellType_ExpressInfo: {
            self.descLabel.text = @"快递信息";
            if (model.comp.length == 0) {
                self.contentLabel.text = @"暂未生成快递信息";
            } else {
                self.contentLabel.text = [NSString stringWithFormat:@"%@ %@",model.comp, model.compNum];
                //复制
                self.copyButton.hidden = NO;
                [_contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.right.equalTo(self.contentView).offset(-68);
                }];
            }
            break;
        }
        case SEGWinRecordDetailNormalCellType_CardNo: {
            self.descLabel.text = @"卡号";
            self.contentLabel.text = model.cardNum;
            self.contentLabel.numberOfLines = 0;
            break;
        }
        case SEGWinRecordDetailNormalCellType_Password: {
            self.descLabel.text = @"密码";
            self.contentLabel.text = model.cardPass;
            self.contentLabel.numberOfLines = 0;
            break;
        }
        case SEGWinRecordDetailNormalCellType_InvaildTime: {
            self.descLabel.text = @"奖品失效时间";
            NSString *time = [SEGUtils stringDateByFormatString:@"yyyy年MM月dd日 HH:mm" withDate:[NSDate dateWithTimeIntervalSince1970:[model.prizeTime doubleValue]]];
            self.contentLabel.text = time;
            break;
        }
    }
}

- (void)seg_copyButtonPressed
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.contentLabel.text;
    // 和安卓统一 复制的时候，复制快递公司和单号
    //pasteboard.string = [self.contentLabel.text componentsSeparatedByString:@" "][1];
    [SEGAlertView showTmepMessageWithMessage:@"复制成功"];
}

- (UIButton *)copyButton
{
    if (!_copyButton) {
        _copyButton = [[UIButton alloc] init];
        [_copyButton setTitle:@"复制" forState:UIControlStateNormal];
        [_copyButton setTitleColor:kColor_T forState:UIControlStateNormal];
        _copyButton.titleLabel.font = kFont_13;
        _copyButton.layer.masksToBounds = YES;
        _copyButton.layer.cornerRadius = 2;
        _copyButton.layer.borderColor = kColor_T.CGColor;
        _copyButton.layer.borderWidth = 0.5;
        [_copyButton addTarget:self action:@selector(seg_copyButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_copyButton];
        [_copyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.width.mas_equalTo(40);
            make.height.mas_equalTo(18);
        }];
    }
    return _copyButton;
}

@end
